package SingleMachineArrangeImpl;

import java.util.Arrays;
/*2.2 最大延迟问题*/
//最早交货期优先（不允许中断）
public class EDD extends SingleMachineArrange{
    @Override
    public void solve() {
        if (process == null || due == null) {
            process = new int[]{3, 1, 4, 1, 3, 2};
            due = new int[]{2, 10, 6, 4, 11, 12};
        }
        int n = process.length;
        //延迟
        int[] lateness = new int[n];
        final int COMPLETE = -1;

        //当前工件加工时间
        int t;
        //总加工时间
        int tt = 0;
        System.out.print("EDD = [");
        for (int i = 0; i < n; i++) {
            //找到交货期最小的工件
            int md = Integer.MAX_VALUE;
            int imd = -1;
            for (int j = 0; j < n; j++) {
                if (due[j] == COMPLETE) continue;
                if (md > due[j]) {
                    md = due[j];
                    imd = j;
                }
            }
            System.out.print((imd+1) + ", ");
            t = process[imd];
            tt += t;
            lateness[imd] = tt - due[imd];
            due[imd] = COMPLETE;
        }
        System.out.println("]");
        System.out.println("lateness = " + Arrays.toString(lateness));
    }
}
